let fs = require('fs');

// 1. 创建/删除 目录
// fs.mkdir("dirFS", (err) => {});
// fs.rmdir("dirFs", (err) => {});

// // 2. 创建/删除 文件
// fs.write()
// fs.unlink("writeMe.txt", (err) => {});

fs.rename()
fs.mkdir("dirFS", (err) => {
	fs.readFile("./readMe.txt", "utf-8", (err, data) => {
		console.log("读取文件完成");
		fs.writeFile("./dirFS/writeMe.txt", "readMe.txt 文件的内容复制给你：\n" + data, (err) => {
			console.log("写入文件完成");
			console.log("copy finishing");
		})
	})
});


let fs = require('fs')
let path = require('path')
let readDirArry = fs.readdirSync('./pic')


console.log(readDirArry)
renFile(readDirArry)

function renFile (fileArr, path) {
	console.log(__dirname)
	let len = fileArr.length;
	let preName;
	let curName = fileArr[0]
	for (let i = 0; i < len; i++) {
		preName = curName;
		if (i == 0) {
			let lastName = fileArr[len - 1];
			// 最后一个文件重命名
			console.log(fileArr[len - 1])
			fs.renameSync(join(fileArr[len - 1]), join("zzz"), err => {});
			fs.renameSync(join(fileArr[0]), join("go.jpg"), err => {});
		} else if (i === len -1){
			fs.renameSync(join("zzz"), join(preName), err => {});
		} else {
			curName = fileArr[i];
			fs.renameSync(join(fileArr[i]), join(preName), err => {});
		}
	}
	console.log("ik",fileArr);	
}
function join (file) {
	return './pic/' + file;
}


 